package xdu.lz.stage2_design_pattern.chapter4_shared_resource_pattern;


//SharedResource
public class Gate {
    private int counter =0;
    private String name = "Nobody";
    private String address = "Nowhere";

    //临界值
    public synchronized void pass(String name, String address){
        //竞争
        this.counter ++;
        this.name = name;
        this.address = address;
        verify();
    }

    private void verify() {
        if(this.name.charAt(0) != this.address.charAt(0)){
            System.out.println("***BROKEN****"+toString());
        }
    }

    @Override
    public String toString() {
        return "No."+counter+":"+name+","+address;
    }
}
